package com.mark.web.data.controller.seller;

import com.mark.common.CurrentUser;
import com.mark.common.ServerResponse;
import com.mark.web.data.entity.po.Product;
import com.mark.web.data.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Description: 卖家对商品的操作
 * @Author: Mark
 * @CreateDate: 2018/8/14.
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
// TODO: 2018/8/14 url应该重新命名 
@RestController
@RequestMapping("/product/")
public class SellerProductController {
    @Autowired
    private IProductService iProductService;


    //1.保存商品（添加，更新）
    @PostMapping(value = "save_product.do")
    public ServerResponse productSave(Product product){
        product.setOwnerId(CurrentUser.getCurrentUserId());
        return iProductService.insertOrUpdateProduct(product);
    }

    //2.修改产品销售状态
    @PostMapping(value = "set_sale_status.do")
    public ServerResponse setSaleStatus(Integer productId,Integer status){
        return  iProductService.setSaleStatus(productId,status);
    }

    //3.获取商品详情
    @PostMapping(value = "seller_product_detail.do")
    public ServerResponse productSellerDetail(Integer productId){
        return iProductService.getProductDetail(productId);
    }

    //4.商品按创建时间升序分页显示
    @PostMapping(value = "seller_product_list.do")
    public ServerResponse getList(Integer ownerId,
                                  @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                  @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        return iProductService.getProductList(pageNum,pageSize,ownerId);
    }

    //5.商品搜索：（1：按商品名模糊搜索）（2：按Id搜索）（3：按状态搜索）
    @PostMapping(value = "search_product.do")
    public ServerResponse searchProduct(String productName,
                                        Integer productId,
                                        Integer status,
                                        Integer ownerId,
                                        @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                        @RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
        return iProductService.searchProduct(ownerId,productName,productId,status,pageNum,pageSize);
    }

    //6.卖家数据统计
    @PostMapping(value = "seller_pro_data.do")
    public ServerResponse getSellerProData(){
        return iProductService.getSellerProData(CurrentUser.getCurrentUserId());
    }






}
